package ssm.myspring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

public class MyBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean{
    private BeanFactory beanFactory;

    private String name;

    private String tag;

    public MyBean(){
        System.out.println("调用构造器实例化Bean");
    }

    public void printName(){
        System.out.println("MyBean name is: " + name);
    }

    public String getTag() {
        return tag;
    }
    public void setTag(String tag) {
        this.tag = tag;
        System.out.println("设置Bean的属性为：" + tag);
    }
    public void destroy() throws Exception {
        // TODO Auto-generated method stub
        System.out.println("调用DisposableBean接口的destroy方法");
    }
    public void afterPropertiesSet() throws Exception {
        // TODO Auto-generated method stub
        System.out.println("调用InitializingBean接口的afterPropertiesSet方法");
    }
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        // TODO Auto-generated method stub
        this.beanFactory = beanFactory;
        System.out.println("调用BeanFactoryAware接口的setBeanFactory方法");
    }
    public void setBeanName(String name) {
        // TODO Auto-generated method stub
        this.name = name;
        System.out.println("调用BeanNameAware接口的setBeanName方法");
    }
}
